Eyeshot 11 Documentation
WinForms Control / Tutorials / How to compute the cumulative transformation of a BlockReference hierarchy tree
In This Topic
    How to compute the cumulative transformation of a BlockReference hierarchy tree
    In This Topic

    Suppose you have a nested BlockReference tree, to compute the cumulative transformation that will be applied to the leaf of the tree you need to multiply in cascade the transformation of each BlockReference.

    The transformation of a BlockReference is given by the BlockReference.Transformation multiplied by the inverse translation of its Block.BasePoint. The code below demonstrates how to compute the cumulative transformation of a tree of BlockReference. Each node of the tree, meaning each block, contains just another BlockReference except for the leaf which contains the actual entity.

    private Transformation GetTransformation(BlockReference br) 
    { 
       Block b = viewportLayout1.Blocks[br.BlockName]; 
    
       Transformation innerTransf; 
    
       if (b.Entities[0] is BlockReference) // Get the transformation of the subtree 
       {
           innerTransf = GetTransformation((BlockReference)b.Entities[0]); 
       }
       else 
       { 
           innerTransf = new Identity(); // I arrived at the leaf 
       } 
    
       // return the cumulative transformation 
       return br.Transformation * new Translation(-b.BasePoint.X, -b.BasePoint.Y, -b.BasePoint.Z) * innerTransf; 
    }
    Private Function GetTransformation(br As BlockReference) As Transformation
        Dim b As Block = ViewportLayout1.Blocks(br.BlockName)
    
        Dim innerTransf As Transformation
        If TypeOf b.Entities(0) Is BlockReference Then
            ' Get the transformation of the subtree 
            innerTransf = GetTransformation(DirectCast(b.Entities(0), BlockReference))
        Else
    
            ' I arrived at the leaf 
            innerTransf = New Identity()
        End If
    
        ' return the cumulative transformation 
        Return br.Transformation * New Translation(-b.BasePoint.X, -b.BasePoint.Y, -b.BasePoint.Z) * innerTransf
    End Function